import React from 'react';
import { Button } from 'antd';
import { WeaTab,WeaLocaleProvider } from 'ecCom';
import { WeaTableNew } from 'comsMobx';
import Condition from "../task/list/Condition";
import { observer } from 'mobx-react';
import { ExcelTemplateViewUrl } from '../../constants/excelTemplate';
import route from '../../constants/route';
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class TemplateList extends React.Component {
    constructor(props) {
        super(props);
        window.openExcelTemplateToView = this.view
    }

    render() {
        const { store } = this.props;
        const { tableStore } = store;
        return (
            <div className="edc-excel-template-list">
                <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@a3hmtc`}
                    datas={[]}
                    searchType={['base', 'advanced']}
                    onSearch={store.quickSearch}
                    onSearchChange={store.changeQuickSearchValue}
                    searchsBaseValue={store.quickSearchValue}

                    showSearchAd={store.conditionVisible}
                    setShowSearchAd={store.setConditionVisible}
                    buttonsAd={this.getConditionButtons()}
                    searchsAd={<Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@y35ggk`} store={store} />}
                />
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@fsaiqn`}
                    comsWeaTableStore={tableStore}
                    needScroll={true}
                    hasOrder={true}
                    register_table={store.reloadTable}
                    // uniqueId={true}
                    onOperatesClick={this.operateClick}
                />
            </div>
        )
    }
    view = (key) => {
        window.open(`${ExcelTemplateViewUrl}#/${route.excelTemplateView}?id=${key}`);
    }
    down = ({ randomFieldId }) => {
        const { store } = this.props;
        store.down(randomFieldId);
    }
    edit = ({ randomFieldId }) => {
        const { store } = this.props;
        store.edit(randomFieldId);
    }
    operateClick = (record, index, operate, flag) => {
        if (flag === 'edit') {
            this.edit(record);
        } else if (flag === 'down') {
            this.down(record);
        }
    }
    getConditionButtons = () => {
        const { store } = this.props;
        return [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zg7cyo@search`} type="primary" onClick={store.search}>{getLabel(388113,'搜索')}</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@r3frzn@reset`} type="ghost" onClick={store.clearCondition}>{getLabel(2022,'重置')}</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1lz36p@cancel`} type="ghost" onClick={store.hideCondtion}>{getLabel(31129,'取消')}</Button>)
        ]
    }
}